package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户激活的后台入口
 *
 * 从第三方邮件收到邮箱内容
 * http://localhost:8080/RaclMall_System_admin_war_exploded/active?code=9502E36DDCAA4A1998E2CF39C5BB0393
 */

@WebServlet("/active")
public class UserActiveServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //1)接收参数
               String code = request.getParameter("code");
        //2)调用用户业务接口
        UserService userService = new UserServiceImpl() ;
        User user = userService.getCode(code) ;

        if(user==null){
            //用户不存在,激活失败
            request.setAttribute("msg","用户激活失败,请重新激活");
        }else{
            //存在
            request.setAttribute("msg","恭喜您,用户激活成功,请<a href='http://localhost:8080/RaclMall_System_admin_war_exploded/jsp/login.jsp'>登录</a>");
        }
        //请求转发到消息页面上
        request.getRequestDispatcher("/jsp/msg.jsp").forward(request,response);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }
}
